	
	
	var projectServiceTable = function(){
		return matchTable('#datatables','/buyService/getBuyServiceProjectPageData.do',listArr,function(obj){
			obj.serviceId = $("#serviceId").val();
			obj.memberId = $("#memberId").val();
			obj.investmentType = $("#investmentType").val();
			obj.buyStartDate = $("#buyStartDate").val();
			obj.buyEndDate = $("#buyEndDate").val();
		},true);
	} 
	
	

$(function(){
	
	
	projectServiceTable();
	
	getSelectMemberInfo("#memberId");
	
	getSelectProjectService("#serviceId");
	
	getSelectInvestmentType("#investmentType");
	
	//查询
	$(".vdrallsearch").on('click',function(){
		projectServiceTable().draw();
	});
	
	//重置
	$(".resetSearchForm").on('click',function(){
		$("#investmentType").html('<option value="">请选择投资种类</option>').trigger("change");
		$("#memberId").html('<option value="">请选择会员</option>').trigger("change");
		$("#serviceId").html('<option value="">请选择服务</option>').trigger("change");
        $("#excel")[0].reset();
	});
    
  //单击行选中事件
    $('#datatables tbody').on('click', 'tr', function () {
        var table = $('#datatables').DataTable();
        var data = table.row(this).data();
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
            $('#check' + data.id).prop("checked", false);
        } else {
            $(this).addClass('selected');
            $('#check' + data.id).prop("checked", true);
        }
    });
    

    
  //全选事件
    $(".checkall").click(function () {
        var check = $(this).prop("checked");
        $(".checkchild").prop("checked", check);
        var cells = new Array();
        $('#datatables tbody tr').each(function () {
            if (check) {
                $(this).addClass('selected');
            } else {
                $(this).removeClass('selected');
            }
        });
    });
    
    
    $(".serviceInfoAdd").on('click',function(){
    	
    	layer.open({
		  type : 2,
		  title: '新增', 
		  skin: 'demo-class',
		  offset : '5%',
		  content: webroot + "/buyService/toAddBuyServiceProject.do",
		  area: ['700px','80%']
		});
    	
    });
    
    
  //删除
    $(".serviceInfoDel").on('click', function () {
        var c_tIds="";
        var choose_a = $("#datatables tbody :checkbox:checked");
        $.each(choose_a, function (n) {
            if (n == 0) {
            	c_tIds = choose_a.eq(n).val();
            } else {
            	c_tIds = c_tIds + "," + choose_a.eq(n).val();
            }
        })
        if (c_tIds == undefined || $.trim(c_tIds) == "") {
        	layer.msg("请选择一条记录！");
            return false;
        }
        if (confirm("确定要作废" + choose_a.length + "条记录？")) {
        	$.ajax({
        		url : webroot + '/buyService/deleteMemberBuyServiceById.do',
        		data : {'ids':c_tIds},
        		type : 'post',
        		dataType : 'json',
        		success : function(result){
        			layer.msg(result.msg);
        			if(result.type=='2'){
        				projectServiceTable().draw();
        			}
        			
        		}
        	});
        }
    });
});

function toEditForm(id){
	
	layer.open({
		  type : 2,
		  title: '修改', 
		  skin: 'demo-class',
		  offset : '5%',
		  content: webroot + "/buyService/toEditMemberBuyService.do?id="+id,
		  area: ['700px','80%']
		});
}

function rejectRenew(id){
	
	if (confirm("确定拒绝续约吗？")) {
    	$.ajax({
    		url : webroot + '/buyService/updateIfRenew.do',
    		data : {'id':id,'type': '0'},
    		type : 'post',
    		dataType : 'json',
    		success : function(result){
    			layer.msg(result.msg);
    			if(result.type=='2'){
    				projectServiceTable().draw();
    			}
    			
    		}
    	});
    }
}

